package com.itedge.solutionmanager.taskdata.solution.inbox;

import java.text.SimpleDateFormat;
import java.util.Locale;

import org.activiti.engine.task.Task;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

import com.itedge.infrastructure.constants.InfrastructureConstants;
import com.itedge.solutionmanager.constants.SolutionManagerConstants;
import com.itedge.solutionmanager.domain.impl.Solution;

/**
 * wrappper class for solution inbox task data, aggregating some fields from 
 * Solution, Customer and Task objects
 * */
public class SolutionTaskInboxData {
	
	private String createTime;
	private String taskName;
	private String taskId;
	private String procId;
	private String solutionName;
	private Long solutionId;
	private String customerName;
	private Long customerId;
	
	public SolutionTaskInboxData(Solution solution, Task task, ReloadableResourceBundleMessageSource messageSource,  Locale currentLocale) {
		String notAssigned = SolutionManagerConstants.UNDEFINED_MESSAGE_BUNDLE;
		if (messageSource != null) {
			this.taskName = messageSource.getMessage(task.getName(), null, 
					InfrastructureConstants.UNDEFINED_MESSAGE, currentLocale);
			notAssigned = messageSource.getMessage(SolutionManagerConstants.CUST_NOT_ASSIGNED, null, 
					SolutionManagerConstants.CUST_NOT_ASSIGNED, currentLocale);
		} else {
			this.taskName = SolutionManagerConstants.UNDEFINED_MESSAGE_BUNDLE;
		}
		this.taskId = task.getId();
		this.procId = task.getProcessInstanceId();
		this.solutionName = solution.toString();
		this.solutionId = solution.getId();
		this.customerName = solution.getCustomer() == null ? 
				notAssigned : solution.getCustomer().getName();
		this.customerId = solution.getCustomer() == null ? -1 : solution.getCustomer().getId();
		
		SimpleDateFormat sdf = new SimpleDateFormat(InfrastructureConstants.ISO_DATE_TIME_FORMAT);		
		this.createTime = sdf.format(task.getCreateTime());
	}
	
	public String getCreateTime() {
		return this.createTime;
	}
	
	public String getTaskName() {
		return this.taskName;
	}
	
	public String getTaskId() {
		return this.taskId;
	}
	
	public String getSolutionName() {
		return this.solutionName;
	}
	
	public Long getSolutionId() {
		return this.solutionId;
	}
	
	public String getCustomerName() {
		return this.customerName;
	}
	
	public Long getCustomerId() {
		return this.customerId;
	}

	public String getProcId() {
		return procId;
	}

	public void setProcId(String procId) {
		this.procId = procId;
	}
	
}